extends Card


func play_on_release(card_view: CardView) -> void:
	var monster: Monster = Globals.current_monster
	var player = card_view.get_tree().get_first_node_in_group("player")
	if CardManager.round_data.anger_addition_times == 0:
		CardManager.round_data.anger_addition_times += 1
		CardManager.round_data.anger_addition_card.push_back(self)
	var tween := card_view.create_tween()
	player.play_animation("attack")
	tween.tween_callback(Shake.shake.bind(monster, 16, 0.2))
	tween.tween_callback(
		func(): Events.take_damage.emit(player, monster, get_final_damage(monster.state))
	)
	#这里一定要比上面的参数大，要不然可能有线程问题，因为shake方法也是个tween实现的
	tween.tween_interval(0.21)
	await tween.finished
	player.play_animation("default")
	card_view.play_on_release_signal_finish.emit()


func get_desc() -> String:
	if desc_lab == "":
		return ""
	var text = (
		desc_lab
		% [get_final_damage(), self.consume_anger, self.anger_addition, self.max_consume_anger]
	)
	return text


func get_desc_on_target(target: Monster) -> String:
	CardManager.round_data.anger_addition_times += 1
	CardManager.round_data.anger_addition_card.push_back(self)
	var all_damage = get_final_damage()
	var no_anger_shield = Globals.get_final_damage(Globals.player_state, target.state, damage, 0)
	var anger_damage = all_damage - no_anger_shield
	var damage_str = ""
	if anger_damage == 0:
		damage_str = str(all_damage)
	else:
		damage_str = str(all_damage) + "(" + str(anger_damage) + ")"
	var lab = (
		desc_lab
		% [
			damage_str,
			self.consume_anger,
			self.anger_addition,
			self.max_consume_anger
		]
	)
	CardManager.round_data.anger_addition_times -= 1
	CardManager.round_data.anger_addition_card.pop_back()
	return lab


func init_from_csv(introduce):
	super.init_from_csv(introduce)
	self.damage = int(introduce[5])
	self.consume_anger = int(introduce[6])
	self.anger_addition = int(introduce[7])
	self.max_consume_anger = int(introduce[8])
